-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Remove leftover ZEND_CAST code for (unset) cast. #5042
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LG with nits.
@@ -5730,12 +5730,6 @@ ZEND_VM_COLD_CONST_HANDLER(51, ZEND_CAST, CONST|TMP|VAR|CV, ANY, TYPE) | |||
expr = GET_OP1_ZVAL_PTR(BP_VAR_R); | |||
|
|||
switch (opline->extended_value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add an assert along the lines of ZEND_ASSERT(opline->extended_value != _IS_BOOL && "Must use ZEND_BOOL instead");
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ZEND_ASSERT(opline->extended_value == IS_OBJECT);
I added would also fail for that same assertion, just later in the program execution. There weren't any early returns I saw.
Added anyway to default:
ext/opcache/Optimizer/dce.c
Outdated
@@ -106,6 +106,7 @@ static inline zend_bool may_have_side_effects( | |||
case ZEND_IS_SMALLER: | |||
case ZEND_IS_SMALLER_OR_EQUAL: | |||
case ZEND_CASE: | |||
/* TODO: Can ZEND_CAST throw when converting object to array (in custom handlers for zend_get_properties_for?) */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say yes. Throwing is not handled by this function though, but by zend_may_throw.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed comment
@@ -4630,8 +4605,9 @@ int zend_may_throw(const zend_op *opline, const zend_op_array *op_array, zend_ss | |||
case IS_ARRAY: | |||
return (t1 & MAY_BE_OBJECT); | |||
case IS_OBJECT: | |||
return (t1 & MAY_BE_ARRAY); | |||
return 0; | |||
default: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace with EMPTY_SWITCH_DEFAULT_CASE()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Followup for d74d392 Attempting to require a file with (unset) casts results in an E_COMPILE_ERROR that can't be caught or handled by set_exception_handler/set_error_handler. Also remove the (bool) cast, because the ZEND_BOOL opcode handles that. Remove inference that array -> object cast can throw. It was added in 2a286ad - I don't know how creating an stdClass would throw. (numeric keys, references, etc. don't cause it to throw)
2a6f936
to
2903737
Compare
Followup for d74d392
Attempting to require a file with (unset) casts results in an E_COMPILE_ERROR
that can't be caught or handled by set_exception_handler/set_error_handler.
Also remove the
_IS_BOOL
handlers, because the ZEND_BOOL opcode handles that (emitted by zend_compile.c).Remove inference that array -> object cast can throw.
It was added in 2a286ad - I don't know how creating an stdClass would throw.
(numeric keys, references, etc. don't cause it to throw, and out of memory would be a fatal error)
$x = (object)$x
. (ZEND_CAST then ZEND_ASSIGN).